package fr.cnam.projetSiw.client.structure.pages.description;

import com.google.gwt.core.client.GWT;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.FlowPanel;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.HasVerticalAlignment;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Image;
import com.google.gwt.user.client.ui.Widget;

import fr.cnam.projetSiw.client.ressources.GeneralBundle;
import fr.cnam.projetSiw.shared.Artist;
import fr.cnam.projetSiw.shared.MusicEvent;

public class DescEventViewImpl extends Composite implements DescEventView
{

	@UiField
	HTML lblDesc;

	@UiField
	HTML lblVille;

	@UiField
	HTML lblPays;

	@UiField
	HTML lblSite;

	@UiField
	HTML lblArtistes;

	@UiField
	HTML titre;

	@UiField
	FlowPanel pnlImage;

	@UiField
	HorizontalPanel hp;

	private static DescEventViewImplUiBinder uiBinder = GWT.create(DescEventViewImplUiBinder.class);

	interface DescEventViewImplUiBinder extends UiBinder<Widget, DescEventViewImpl>
	{
	}

	private Presenter presenter;

	public DescEventViewImpl()
	{
		initWidget(uiBinder.createAndBindUi(this));
		hp.setVerticalAlignment(HasVerticalAlignment.ALIGN_MIDDLE);
	}

	@Override
	public void setPresenter(ZicPresenter presenter)
	{
		this.presenter = (Presenter) presenter;
	}

	@Override
	public void setData(MusicEvent result)
	{
		if (result == null)
			return;
		titre.setText(result.getName());
		titre.addStyleName(GeneralBundle.INSTANCE.css().titleSquare());
		titre.addStyleName(GeneralBundle.INSTANCE.css().colorBlue());

		lblVille.setText(result.getCity().getName());

		lblPays.setText(result.getCity().getCountryName());
		lblSite.setHTML(result.getWebSite());
		lblDesc.setText(result.getDescription());
		pnlImage.add(new Image(result.getEventImg()));
		for (Artist a : result.getAssociatedArtist())
		{
			if (lblArtistes.getText().isEmpty())
				lblArtistes.setText(a.getName());
			else
				lblArtistes.setText(lblArtistes.getText() + "," + a.getName());
		}
	}

}
